﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_AddOldMailAttch]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_AddOldMailAttch];
GO
CREATE PROCEDURE [dbo].[sproc_AddOldMailAttch]
    @FileIDS nvarchar(255),
    @Finished bit=1
/*

=====================================================

功能:    转发时,把老邮件中的附件添加到新邮件里去
参数:
    @FileIDS         被转发的附件文件ID
    @Finished bit=1        是否除去新邮件的关联标记
=====================================================

*/
AS


DECLARE @SQl nvarchar(2000)
IF LEN(@FileIDS)>0
BEGIN
    SET @SQl = 'Insert Into UDS_FILES ([DOCID],[FileName],[FileSize],[FileAttribute],[FileVisualPath],[FileAuthor],[FileCatlog],[FileAddedDate]) SELECT a.DOCID,b.[FileName],b.FileSize,b.FileAttribute,b.FileVisualPath,b.FileAuthor,b.FileCatlog,getdate() FROM UDS_DOCUMENT a,UDS_FILES b WHERE a.DOCATTRIBUTE =1 AND a.DOCSIGN = @@SPID and b.FileID in (' + @FileIDS + ')'
    
    ---执行动态SQL语句
    Exec (@SQl)
    
END 
IF @Finished =1
    UPDATE uds_document
        SET DOCATTRIBUTE =0,DOCSIGN=0 
        WHERE DOCATTRIBUTE =1 AND DOCSIGN = @@SPID